define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'analyze/index' + location.search,
                    add_url: 'analyze/add',
                    edit_url: 'analyze/edit',
                    del_url: 'analyze/del',
                    multi_url: 'analyze/multi',
                    import_url: 'analyze/import',
                    table: 'analyze',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',

                // todo  单独处理的  start
                search:false,            // 右侧模糊检索去掉
                showToggle: false,       // 浏览模式切换
                showColumns: false,      // 切换字段
                showExport: false,       // 隐藏导出
                searchFormVisible: true,  // 通用搜索是否直接显示
                // todo  单独处理的  end

                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'k_type', title: __('K_type'), searchList: {"0":__('K_type 0'),"1":__('K_type 1'),"2":__('K_type 2'),"3":__('K_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'k_val', title: __('K_val'), operate: 'LIKE'},
                        {field: 'independent_visitors', title: __('Independent_visitors'),operate: false},
                        {field: 'lp_views', title: __('Lp_views'),operate: false},
                        {field: 'completed_orders', title: __('Completed_orders'),operate: false},
                        {field: 'abandoned_orders', title: __('Abandoned_orders'),operate: false},
                        {field: 'mall_type', title: __('Mall_type'), searchList: {"1":__('Mall_type 1'),"2":__('Mall_type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'date', title: __('Date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
